/*
*  find_patterns.h
*
*
*  Created by Martin Neururer on 9/30/09.
*  Copyright 2009 ITBA. All rights reserved.
*
*/

#ifndef _FIND_PATTERNS_H_
#define _FIND_PATTERNS_H_

	#ifdef _CH_
		#pragma package <opencv>
	#endif
	
	#ifndef _EiC
		#include "cv.h"
		#include "highgui.h"
		#include <stdio.h>
	#endif

	#define TOLERANCE 2.0f
	#define ARRAY_MAX_CAPACITY 1200


	// parameter structure to represent a right angle between two line segments.
	typedef struct param {
		double dMinDist;				// shortest distance between the ends of the line segments.
		double dAngle;					// angle between the line segments.
		double dLineLength[2]; 	// length of both line segments.
		double dAngleOrient;		// orientation of the angle (to the x axis) that the line segments are forming.
		CvPoint vertexPos;			// position of the vertex of this angle.
 	} rightAngle; // data size: 48 bytes.

	// static array to store the angle parameters that the filtered line segments are forming ...
	static rightAngle angleParamList[ARRAY_MAX_CAPACITY];

	// enumeration to define the result
	typedef enum val { INTERESECTING, NOT_INTERESECTING, COINCIDENT, PARALLEL } intersectResult;


	/// geometric calculation methods:
	static double angle(CvPoint *pPtA1, CvPoint *pPtA2, CvPoint *pPtB1, CvPoint *pPtB2);
	static double lineOrient(CvPoint *pPtA, CvPoint *pPtB);
	static double lineLength(CvPoint *pPtA, CvPoint *pPtB);
	static double minDistance(CvPoint *pPtA1, CvPoint *pPtA2, CvPoint *pPtB1, CvPoint *pPtB2);
	static int calcVertexPos(CvPoint *pPtA1, CvPoint *pPtA2, CvPoint *pPtB1, CvPoint *pPtB2, CvPoint *pIntPt);
	/// methods to find geometric figures in an image:
	int findRectangles(IplImage *pImg, CvSeq *pLineSeq);
	//int findRectangles(IplImage *pImg, CvSeq *jod);
	void findTriangles(IplImage *pImg, CvMemStorage *pMemStorage, CvSeq *pLineSeq);

#endif